/**
 * Created with JetBrains PhpStorm.
 * User: lunjiang
 * Date: 13-1-23
 * Time: 下午3:29
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    /**
     *
     * @type {Array}
     * key='2012-08' //X轴 时间
     * pnum 计划编制
     * anum 在职人数
     * p P线人数
     * m M线人数
     */
    //var dataSource1 = [{'2012-08':{pnum:1235,anum:1200,p:1000,m:200}},{'2012-09':{pnum:1205,anum:1100,p:1000,m:200}},{'2012-10':{pnum:1235,anum:1200,p:1000,m:200}},{'2012-11':{pnum:1235,anum:1200,p:1000,m:200}},{'2012-12':{pnum:1235,anum:1200,p:1000,m:200}},{'2013-01':{pnum:1235,anum:1200,p:1000,m:200}}];//计划编制
    //var dataSource = eval('('+data_list+')');
     //var dataSource=[{"pnum":0,"anum":5,"p":"10","m":"10","time":"2012-07"},{"pnum":0,"anum":11,"p":"10","m":"10","time":"2012-08"},{"pnum":0,"anum":12,"p":"10","m":"10","time":"2012-09"},{"pnum":0,"anum":12,"p":"10","m":"10","time":"2012-10"},{"pnum":0,"anum":12,"p":"10","m":"10","time":"2012-11"},{"pnum":0,"anum":17,"p":"10","m":"10","time":"2012-12"}];

    var  dataSource = eval('('+data_list+')');
    if(!dataSource){
        $("#container").html('<div style="color: red;font:20px;margin: 100px auto;text-align: center;">暂无数据!!!</div>')
        return;
    }
    //logic operator
  //  var len = dataSource.length;
  //  alert(len);
    var xAxis = [];
    var pDataSource = [];//计划纺制
    var aDataSource = [];//在职人数

    $.each(dataSource,function(i,v){
        pDataSource.push(v.pnum);
        aDataSource.push(v.anum);
        xAxis.push(v.time);
    });

    /*for(var i = 0;i<len;i++){
            pDataSource.push(dataSource[i].pnum);
            aDataSource.push(dataSource[i].anum);
            xAxis.push(dataSource[i].time);
    }*/

    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container'
            //type: 'lin'
        },
        title: {
            text: ''
        },

        xAxis: {
            categories: xAxis
        },
        yAxis: {
            title: {
                text: ''
            },
          min:y_minDate
        },
        tooltip: {
            enabled: true,
            formatter: function() {
                for(var i= 0,len=dataSource.length;i<len;i++){
                    for(var j in dataSource[i]){
                        if(dataSource[i].time == this.x){
                            var obj = dataSource[i];
                            var html = this.x +'在职人数为'+obj.anum+'<br/>P线'+ obj.p+'人,'+'M线'+ obj.m+'人<br/>';
                            html = html + '<span style="color: #f39547">（计划编制为'+obj.pnum+'人）</span>';
                            return html;
                        }
                    }
                }
            }
        },
        legend:{
            itemWidth:100
        },
//        plotOptions: {
//            line: {
//                dataLabels: {
//                    enabled: true
//                },
//                enableMouseTracking: false
//            }
//        },
        series: [{
            name: '计划编制',
            data: pDataSource,
            color:"#ef7612"

        }, {
            name: '在职人数',
            data: aDataSource,
            color:"#909090"
        }]
    });

    /**
     *
     * @type {Array}
     * time:时间
     * dimissReate:离职率
     * total:离职总人数
     * vnum:主动离职人数
     * pnum:被动离职人数
     */
   /* var dataSource = [{time:'2011年-第1季度',dimissRate:0.10,total:100,vrate:0.08,vnum:10,prate:0.02,pnum:90},
        {time:'2011年-第2季度',dimissRate:0.20,total:100,vrate:0.08,vnum:10,prate:0.12,pnum:90},
        {time:'2011年-第3季度',dimissRate:0.11,total:100,vrate:0.03,vnum:10,prate:0.08,pnum:90},
        {time:'2011年-第4季度',dimissRate:0.21,total:100,vrate:0.08,vnum:10,prate:0.13,pnum:90}];//计划编制


    //logic operator

    var xAxis = [];
    var vDataSource = [];//主动离职
    var pDataSource = [];//被动离职
    var rateSource = [];
    for(var i = 0,len= dataSource.length;i<len;i++){
        xAxis.push(dataSource[i].time);
        vDataSource.push(dataSource[i].vrate);
        pDataSource.push(dataSource[i].prate);
        rateSource.push(dataSource[i].dimissRate);
    }
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            zoomType:'xy'
            //type: 'lin'
        },
        title: {
            text: ''
        },

        xAxis: {
            categories: xAxis,
            lineWidth:1,
            tickmarkPlacement:'on'

        },

        yAxis: {
            title: {
                text: ''
            },
            labels:{
                formatter: function() {
                    return (this.value)* 100+'%';
                }
            }
        },
        tooltip: {
            enabled: true,
            formatter: function() {
                for(var i= 0,len=dataSource.length;i<len;i++){

                        if(dataSource[i].time == this.x){
                            var obj = dataSource[i];
                            var html = this.x +'离职率为'+obj.dimissRate*100+'%<br/>';
                            html = html + '<b>主动'+obj.pnum+'人，被动'+obj.vnum+'人</b>';
                            return html;
                        }

                }
                //var html =this.x在职人数为;
                //return this.x+'-'+this.y;
            }
        },

        legend:{

        },
     series: [{
            name: '离职率',
            data: rateSource,
            stack:"1",
            color:"#ef7612"
        },
           {
            name: '主动离职',
            color: '#adc1dc',
            type: 'column',
            stack:"3",
            data: vDataSource
        }, {
            name: '被动离职',
            color: '#4572A7',
            type: 'column',
            stack:"3",
            data: pDataSource

       }

        ]
    });*/

});